package com.jing.system.comm.contants;

import javax.servlet.ServletConfig;

import org.apache.log4j.Logger;

import com.jing.system.utils.SpringUtil;
import com.taobao.tools.utils.TaobaoConfig;

/**
 * 淘宝常用的类
 * @author jing.yue
 * @version 1.0
 * @since 2012-08-29
 */
public class TaobaoCons {
	private static final Logger logger = Logger.getLogger(TaobaoCons.class);


	/** 淘宝appkey */
	public static String taobao_appkey;

	/** 淘宝appsecret */
	public static String taobao_appsecret;

	/** 淘宝redirectUrl */
	public static String taobao_redirectUrlPrefix;

	/** 淘宝taobao_apiUrl */
	public static String taobao_apiUrl;

	/**
	 * 初始化淘宝常用数据
	 * @param config
	 */
	public static void initTaobaoData(ServletConfig config) {
		Contants contants = (Contants) SpringUtil.getBean("contants");
		taobao_appkey = contants.getTaobao_appkey();
		config.getServletContext().setAttribute("taobao_appkey", taobao_appkey);

		taobao_appsecret = contants.getTaobao_appsecret();
		config.getServletContext().setAttribute("taobao_appsecret", taobao_appsecret);

		taobao_redirectUrlPrefix = contants.getTaobao_redirectUrlPrefix();
		config.getServletContext().setAttribute("taobao_redirectUrlPrefix", taobao_redirectUrlPrefix);

		taobao_apiUrl = contants.getTaobao_apiUrl();
		config.getServletContext().setAttribute("taobao_apiUrl", taobao_apiUrl);

		logger.info("初始化淘宝常用数据: SUCCESS");

		//appkey
		TaobaoConfig.updateProperties(TaobaoConfig.TAOBAO_APPKEY, taobao_appkey);
		//app_secret
		TaobaoConfig.updateProperties(TaobaoConfig.TAOBAO_APPSECRET, taobao_appsecret);
		//回调地址
		TaobaoConfig.updateProperties(TaobaoConfig.TAOBAO_REDIRECTURLPREFIX, taobao_redirectUrlPrefix);
		//apiUrl
		TaobaoConfig.updateProperties("apiUrl", taobao_apiUrl);
		logger.info("初始化淘宝SDK信息: SUCCESS");
	}
}